package com.xudow.app.dynamicstate_old.module.discovery.search;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.list.BeamListFragment;
import com.jude.beam.expansion.list.ListConfig;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.decoration.DividerDecoration;
import com.jude.utils.JUtils;
import com.xudow.app.R;

/**
 * Created by ske on 2016/6/30.
 */
@RequiresPresenter(SearchHistoryPresenter.class)
public class SearchHistoryFragment extends BeamListFragment<SearchHistoryPresenter, String> {
    @Override
    public BaseViewHolder<String> getViewHolder(ViewGroup parent, int viewType) {
        return new SearchHistoryViewHolder(parent);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getListView().addItemDecoration(new DividerDecoration(getResources().getColor(R.color.gray100), JUtils.dip2px(1)));
        getPresenter().getAdapter().setOnItemClickListener(position -> {
            ((SearchActivity) getActivity()).search(getPresenter().getAdapter().getItem(position));
        });
        $(view, R.id.clear).setOnClickListener(v -> {
            JUtils.getSharedPreference().edit().remove("search_history").apply();
            getPresenter().onRefresh();
        });
    }

    @Override
    public ListConfig getConfig() {
        return super.getConfig().setRefreshAble(false).setLoadmoreAble(false).setLoadMoreView(null);
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_search_history;
    }
}
